// Copyright (c) 2002 HTHK
//******************************************************************/
//Modification History
//******************************************************************/
//CR log no 1266: By Ploy Li on 2004-04-27
//******************************************************************/

package com.system.userMultiRole;

import javax.servlet.*;
import javax.servlet.http.*;

import java.io.*;
import java.sql.*;

import com.ffpc.servlet.*;
import com.ffpc.sql.*;
import com.ffpc.struts.StrutsMessage;
import com.ffpc.util.DateFormatter;


public class UserMultiRoleServlet
  extends DBServlet {

  @Override
protected String perform(  HttpServletRequest request,
                             HttpServletResponse response,
                             StrutsMessage message)
    throws  ServletException,
            IOException,
            SQLException,
            DataException,
            Exception
  {

     //CR log no 1054 end of:

      String action = new String(request.getParameter("formAction"));

      UserMultiRoleBean user = UserMultiRoleProcess.createBean();
      user.setUser_id(request.getParameter("user_id"));

      //user.setRole_id(request.getParameter("role_id"));
      String[] gStrRoleID = null;
      if(request.getParameterValues("role_id") != null)
      	gStrRoleID = request.getParameterValues("role_id");
      user.setUpd_user(getUser().getUser_id());
      user.setUpd_date(DateFormatter.format(this.getDate()));
   //CR log no 1054 end of

      if (action.trim().equalsIgnoreCase("Create"))
      {
         user.setCrt_user(getUser().getUser_id());
         user.setCrt_date(DateFormatter.format(this.getDate()));

        if (UserMultiRoleProcess.insert(this.getConnection(),user)>0)
            message.setMessage("Save successfully.");
        else
            message.setMessage("Save failure");
      }
      else if (action.trim().equalsIgnoreCase("Update"))
        if (UserMultiRoleProcess.update(this.getConnection(),user)>0)
            message.setMessage("Save successfully.");
        else
            message.setMessage("Save failure.");
      else if (action.trim().equalsIgnoreCase("Delete"))
        if (UserMultiRoleProcess.delete(this.getConnection(),user)>0)
            message.setMessage("Delete successfully.");
        else
            message.setMessage("Delete failure.");
      else
            message.setMessage("No action mapped!");

         return "system/UserSearch.jsp";


  }
}
